<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\FourPatient;
use App\Models\FourShip;
use App\Models\Typed;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class FourPatientController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new FourPatient(['es','card']), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('patient_name');
            $grid->column('es.ship_name');
            $grid->column('phone');
            $grid->column('card.type_name');
            $grid->column('id_card');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new FourPatient(), function (Show $show) {
            $show->field('id');
            $show->field('patient_name');
            $show->field('ship_id');
            $show->field('phone');
            $show->field('type_id');
            $show->field('id_card');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new FourPatient(), function (Form $form) {
            $form->display('id');
            $form->text('patient_name');
            $form->text('ship_id')->options(FourShip::pluck('ship_name','id')->toArray());
            $form->text('phone');
            $form->text('type_id')->options(Typed::pluck('type_name','id')->toArray());
            $form->text('id_card');
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
